package com.heima.admin.controller.v1;

import com.heima.admin.service.ChannelService;
import com.heima.model.admin.dtos.ChannelDTO;
import com.heima.model.admin.pojos.AdChannel;
import com.heima.model.common.dtos.ResponseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(value = "频道管理controller", tags = "频道管理controller")
@RestController
@RequestMapping("api/v1/channel")
public class ChannelController {

    @Autowired
    private ChannelService channelService;

    @ApiOperation(value = "根据条件分页查询", notes = "根据条件：name status 查询，结果以ord升序查询")
    @PostMapping("/list")
    public ResponseResult findByQuery(
            @RequestBody ChannelDTO dto,
            @RequestHeader(value = "userId",required = false)String id) {
        return channelService.findByQuery(dto);
    }

    @ApiOperation(value = "新增频道")
    @PostMapping("/save")
    public ResponseResult insert(@RequestBody AdChannel adChannel) {
        return channelService.insert(adChannel);
    }

    @ApiOperation("修改频道")
    @PostMapping("/update")
    public ResponseResult update(@RequestBody AdChannel adChannel) {
        return channelService.update(adChannel);
    }

    @ApiOperation("删除频道")
    @GetMapping("/del/{id}")
    public ResponseResult delete(@PathVariable("id") Integer id) {
        return channelService.delete(id);
    }
}
